Skip to content

fix(tracing): finish child spans when blocks unwind - #3207

Open
itsrayeedscodespace wants to merge 1 commit into
getsentry:masterfrom
itsrayeedscodespace:fix/finish-spans-on-block-unwind
Open

itsrayeedscodespace wants to merge 1 commit into
getsentry:masterfrom
itsrayeedscodespace:fix/finish-spans-on-block-unwind

Conversation

@itsrayeedscodespace

@itsrayeedscodespace itsrayeedscodespace commented Nov 14, 2026 •

Copy link
Copy Markdown

Description

Sentry.with_child_span loses spans when the block exits through break, a nonlocal return, throw, or an exception outside StandardError. Span#with_child_span only finishes after a normal yield or in its rescue branch. The hub restores its parent scope, but the child retains a nil timestamp and TransactionEvent excludes it.

Move finalization into ensure, scoped around the block execution. Keep the existing StandardError status handling, exception propagation, and direct Span#with_child_span return value.

Four public-API regression specs fail on unchanged master: the captured transaction has zero child spans. They pass with the fix and verify that the span reaches the transaction event, the parent scope is restored, and control-flow values/original exceptions are preserved. Existing specs continue covering normal completion and StandardError status handling.

Validation (Ruby 3.4.12, committed ruby-3.4_rack-3_redis-4 matrix cell):

  • Targeted API/span specs: 176 examples, zero failures
  • Full core rake suite: 1,670 examples, zero failures, three version-dependent skips
  • Isolated specs: 44 examples, zero failures
  • RuboCop on both changed files: no offenses
  • git diff --check

Fixes #3206
Related: the original exception-handling fix in #1982.

Linear: RUBY-243

Finish child spans in ensure so nonlocal return, break, throw, and exceptions outside StandardError cannot leave unfinished spans that disappear from transaction events. Preserve block control flow, exception propagation, and the direct Span return value.

Co-Authored-By: GPT-6 <gpt-6@noreply.example.com>
@itsrayeedscodespace
itsrayeedscodespace requested review from a team and solnic as code owners November 14, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

with_child_span drops spans when blocks exit via break, return, or throw

1 participant